#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        vector<pair<int, int>> inter;
        for (auto& in : intervals) inter.push_back({ in[0], in[1] });
        sort(inter.begin(), inter.end());
        int ret = 0;
        pair<int, int> tmp;
        tmp.first = inter[0].first, tmp.second = inter[0].second;
        for (int i = 1; i < inter.size(); i++)
        {
            if (tmp.second > inter[i].first) tmp.second = min(tmp.second, inter[i].second), ret++;
            else tmp.first = inter[i].first, tmp.second = inter[i].second;
        }
        return ret;
    }
};